package com.alpha.core.utils;

import java.util.Arrays;

/**
 * 路径工具类
 *
 * @author chenruwan
 * @since 2022-01-01
 */
@SuppressWarnings("unused")
public class PathUtil {
    private PathUtil() {
    }

    public static String combine(String first, String... more) {
        if (more.length == 0) {
            return first;
        }

        StringBuilder builder = new StringBuilder(first);
        // FileUtils.isWindows() ? "\\\\" : "/"
        Arrays.stream(more).forEach(each -> builder.append("/").append(each));

        return builder.toString();
    }

    public static String getParent(String path) {
        if (StringUtil.isEmpty(path)) {
            return path;
        }
        return path.substring(0, path.lastIndexOf('/'));
    }
}
